package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.vo.CatalogVO;
import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.domain.StrategyTheme;
import cn.wolfcode.wolf2w.query.StrategyQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.IStrategyThemeService;
import cn.wolfcode.wolf2w.util.JsonResult;
import cn.wolfcode.wolf2w.util.UploadUtil;
import com.sun.org.apache.xml.internal.resolver.Catalog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.management.Query;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/strategy")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyThemeService strategyThemeService;
    @RequestMapping("/list")
    private String list(Model model, @ModelAttribute("qo") StrategyQuery qo){
       Page<Strategy> page = strategyService.query(qo);
       model.addAttribute("page",page);
       model.addAttribute("toasts", new ArrayList<>());
       return "/strategy/list";
    }
   @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Strategy strategy) {
        System.out.println(strategy);
        strategyService.saveOrUpdate(strategy);
        return JsonResult.success();
    }
   @RequestMapping("/delete")
   @ResponseBody
   public Object delete(String id){

       strategyService.delete(id);

       return  JsonResult.success();
   }
   @RequestMapping("/input")
   public String input(Model model, String id) {


       if(StringUtils.hasLength(id)){
        //编辑strategy
           Strategy strategy = strategyService.get(id);
           model.addAttribute("strategy",strategy);
       }
       //添加
       //攻略主题
       List<StrategyTheme> list = strategyThemeService.getAll();
       model.addAttribute("themes",list);
       //攻略分类分组
       model.addAttribute("catalogs",strategyCatalogService.getgroupList());
       return "strategy/input";
   }
    @GetMapping("/changeState")
    @ResponseBody
    public Object changeState ( int state,String id){
        strategyService.chenagState(state,id);
        return JsonResult.success();
    }


}
